-
Notifications
You must be signed in to change notification settings - Fork 528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FiberRef #1822
FiberRef #1822
Conversation
* Divorces the current reference from parent fiber and | ||
* sets a new reference for the duration of `fa` evaluation. | ||
*/ | ||
def locally(fa: F[A]): F[A] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't that be def locally[B](fb: F[B]): F[B]
? with a new method level type-parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should yeah
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've had a similar case in Resource once... 0bd5660
(#1368)
local <- FiberLocal[Ref[IO, A]](ref) | ||
} yield new FiberRef[IO, A] { | ||
override def locally(fa: IO[A]): IO[A] = { | ||
val acquire = local.get.product(Ref.of[IO, A](default)).flatTap { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Random thought, should this use default
or the current value in the "outer" scope as the initial value instead?
Also, we can save a lot of typing by doing local.get
first and flatMapping over that, but I don't know about the performance.
* Divorces the current reference from parent fiber and | ||
* sets a new reference for the duration of `fa` evaluation. | ||
*/ | ||
def locally(fa: F[A]): F[A] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried using locals (a copy of this PR) to get a separate scope for every test in a weaver suite, but:
- using a normal
IOLocal
is insufficient, as I want to share the scope between fibers forked within a single test - using a
FiberRef
like here works as long as I remember to isolate the scope. Problem is, I don't expose the locals because they're hidden behind some interface (i.e. a tagless algebra). A way to dolocally
with all FiberRefs in existence would be really cool. So pretty much theIO.clearLocals
you mentioned in Fiber locals #1393, but with knowledge ofFiberRef
(just clearing the local doesn't cut it for a Ref because it can be the same value if we're at the start of a test).
with knowledge of
FiberRef
this is probably the worst part.
Not sure what the status is of this PR. Is there a consensus on how to continue here? Feel free to remove it from the milestone if you think it's not going to make it. |
Any consensus on this? It seems like |
Follow up to #1393